package com.ygxsk.carhome.ui.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.enumwrap.SmartGoHasFee;
import com.ygxsk.carhome.enumwrap.SmartGoIsPayment;
import com.ygxsk.carhome.response.SmartGoOutItemBean;
import com.ygxsk.carhome.utils.CommUtils;

import java.util.ArrayList;
import java.util.List;

import cn.bingoogolapple.photopicker.widget.BGANinePhotoLayout;

/*
 * @Author:itchenqi175@163.com
 * @Time:2023-07-17  16:07
 * @Description:车辆智能出门，出门卡券发放的适配器。
 *
 * 智能出门主页列表，智能出门的【更多】历史列表，这个和【核销列表】不是一个适配器；
 *
 * 卡券发放的 历史记录 也是这个
 *
 */
public class SmartGoItemAdapter extends BaseQuickAdapter<SmartGoOutItemBean, BaseViewHolder> {

    private BGANinePhotoLayout.Delegate bgaNinePhotoLayoutDelegate;

    public void setBgaNinePhotoLayoutDelegate(BGANinePhotoLayout.Delegate _bgaNinePhotoLayoutDelegate) {
        bgaNinePhotoLayoutDelegate = _bgaNinePhotoLayoutDelegate;
    }


    public SmartGoItemAdapter(int layoutResId) {
        super(layoutResId);
    }

    public SmartGoItemAdapter(int layoutResId, @Nullable List<SmartGoOutItemBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, SmartGoOutItemBean smartGoOutItemBean) {

        if (smartGoOutItemBean != null) {

            //车牌号
            String vehicleNo = smartGoOutItemBean.getVehicleNo();
            //是否产生费用
            String hasFee = String.valueOf(smartGoOutItemBean.getHasFee());

            //是否产生费用的汉字形式
            String hasFesInfo = "";
            if (TextUtils.equals(SmartGoHasFee.HASFEE_YES.getIndex(), hasFee)) {
                hasFesInfo = SmartGoHasFee.HASFEE_YES.getValue();
            } else if (TextUtils.equals(SmartGoHasFee.HASFEE_NO.getIndex(), hasFee)) {
                hasFesInfo = SmartGoHasFee.HASFEE_NO.getValue();
            }

            //是否已缴费
            String isPayment = String.valueOf(smartGoOutItemBean.getIsPayment());
            String isPaymentInfo = "";
            if (TextUtils.equals(SmartGoIsPayment.PAYMENT_YES.getIndex(), isPayment)) {
                isPaymentInfo = SmartGoIsPayment.PAYMENT_YES.getValue();
            } else if (TextUtils.equals(SmartGoIsPayment.PAYMENT_NO.getIndex(), isPayment)) {
                isPaymentInfo = SmartGoIsPayment.PAYMENT_NO.getValue();
            }

            //业务类型
            String businessType = smartGoOutItemBean.getBusinessTypeName();
            //业务类型 描述
            String description = smartGoOutItemBean.getDescription();
            //发放时间
            String createTime = smartGoOutItemBean.getCreateTime();
            //九宫格图片内容
            ArrayList<String> list = smartGoOutItemBean.getFilesForApp();

            //findviews
            //顶部的一个帮助布局
            TextView textViewHelpInSmartGoout = (TextView) baseViewHolder.getView(R.id.textviewhelpinsmartgoout);
            //车牌号
            TextView textViewCarNumberSmart = (TextView) baseViewHolder.getView(R.id.textviewcarnumbersmart);
            //是否产生费用
            TextView textViewHasFeesSmart = (TextView) baseViewHolder.getView(R.id.textviewhasfeessmart);
            //是否已缴费
            TextView textViewIsPaymentSmart = (TextView) baseViewHolder.getView(R.id.textviewispaymentsmart);
            //业务类型
            TextView textViewBuinessTypeSmart = (TextView) baseViewHolder.getView(R.id.textviewbuinesstypesmart);
            //卡券的发放时间
            TextView textViewDistTimeSmart = (TextView) baseViewHolder.getView(R.id.textviewdisttimesmart);
            //一个帮助布局
            TextView textViewTimeLineBottom = (TextView) baseViewHolder.getView(R.id.textviewtimelinebottom);
            //业务描述，如果文本是空的就不展示
            LinearLayout layoutBuinessDesInfo = (LinearLayout) baseViewHolder.getView(R.id.layoutbuinessdesinfo);
            //业务类型的描述
            TextView textViewBuinessDesInfo = (TextView) baseViewHolder.getView(R.id.textviewbuinessdesinfo);

            //附件布局
            LinearLayout linearLayoutInSmartGoUpLoad = (LinearLayout) baseViewHolder.getView(R.id.linearlayoutinsmartgopload);

            //添加智能出门的九宫格改造
            BGANinePhotoLayout npl_item_moment_photos_in_smartgo = (BGANinePhotoLayout) baseViewHolder.getView(R.id.npl_item_moment_photos_in_smartgo);

            //默认是展示的
            int currentPosition = getItemPosition(smartGoOutItemBean);

            if (currentPosition == 0) {//如果是第一条那么不展示
                textViewHelpInSmartGoout.setVisibility(View.GONE);
            } else {
                textViewHelpInSmartGoout.setVisibility(View.VISIBLE);
            }

            if (!TextUtils.isEmpty(description)) {
                textViewTimeLineBottom.setVisibility(View.GONE);
                layoutBuinessDesInfo.setVisibility(View.VISIBLE);
            } else {
                textViewTimeLineBottom.setVisibility(View.VISIBLE);
                layoutBuinessDesInfo.setVisibility(View.GONE);
            }

            if (list != null && !list.isEmpty()) {
                linearLayoutInSmartGoUpLoad.setVisibility(View.VISIBLE);
            } else {
                linearLayoutInSmartGoUpLoad.setVisibility(View.GONE);
            }

            if (npl_item_moment_photos_in_smartgo != null) {
                npl_item_moment_photos_in_smartgo.setData(list);
            }

            npl_item_moment_photos_in_smartgo.setDelegate(bgaNinePhotoLayoutDelegate);


            CommUtils.setText(textViewCarNumberSmart, vehicleNo);
            CommUtils.setText(textViewHasFeesSmart, hasFesInfo);
            CommUtils.setText(textViewIsPaymentSmart, isPaymentInfo);
            CommUtils.setText(textViewBuinessTypeSmart, businessType);
            CommUtils.setText(textViewDistTimeSmart, createTime);

            CommUtils.setText(textViewBuinessDesInfo, description);

        }
    }
}
